package cn.softcits.thread.abc;

/**
 * @author Rocket
 * @version 10.0.1
 * @date 2021-07-04 9:57 PM
 */
public class PrintLetter {

    private Integer i = 1;

    public synchronized void printA() {
        if(i == 1) {
            System.out.println("Thread 1 is printing A");
            i++;
            this.notify();
        } else {
            try {
                Thread.sleep(1000);
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void printB() {
        if(i == 2) {
            System.out.println("Thread 2 is printing B");
            i++;
            this.notify();
        } else {
            try {
                Thread.sleep(1000);
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void printC() {
        if(i == 3) {
            System.out.println("Thread 3 is printing C");
            i = 1;
            this.notify();
        } else {
            try {
                Thread.sleep(1000);
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
